import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

/// 举报原因类型
enum ReportReason {
  spam('垃圾内容或广告', 'Spam or advertising'),
  inappropriate('不当或冒犯性内容', 'Inappropriate or offensive content'),
  pornographic('色情内容', 'Pornographic content'),
  violence('暴力或威胁', 'Violence or threats'),
  hateSpeech('仇恨言论', 'Hate speech'),
  falseInformation('虚假信息', 'False information'),
  copyright('侵犯版权', 'Copyright infringement'),
  privacy('侵犯隐私', 'Privacy violation'),
  childSafety('危害儿童安全', 'Child safety concerns'),
  block('屏蔽此内容', 'Block this content'),
  other('其他', 'Other');

  final String chineseName;
  final String englishName;

  const ReportReason(this.chineseName, this.englishName);

  @override
  String toString() => englishName;
}

/// 举报底部弹出框组件
class ReportBottomSheet {
  /// 显示举报底部弹出框
  ///
  /// [onReport] 举报回调，返回举报原因
  /// [onSuccess] 举报成功后的回调
  static Future<void> show({
    required Function(ReportReason reason) onReport,
    Function()? onSuccess,
  }) async {
    await Get.bottomSheet(
      _ReportBottomSheetContent(
        onReport: (reason) async {
          // 关闭底部弹出框
          Get.back();

          // 调用举报回调
          await onReport(reason);

          // 显示举报成功提示
          EasyLoading.showSuccess('Report submitted successfully');

          // 调用成功回调
          onSuccess?.call();
        },
      ),
      backgroundColor: Colors.transparent,
      isScrollControlled: true,
    );
  }
}

/// 举报底部弹出框内容
class _ReportBottomSheetContent extends StatelessWidget {
  final Function(ReportReason reason) onReport;

  const _ReportBottomSheetContent({Key? key, required this.onReport})
    : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: const Color(0xFF0F3876),
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(20.r),
          topRight: Radius.circular(20.r),
        ),
      ),
      padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 15.h),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 标题和关闭按钮
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                'Report',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 18.sp,
                  fontWeight: FontWeight.bold,
                ),
              ),
              IconButton(
                icon: Icon(Icons.close, color: Colors.white),
                onPressed: () => Get.back(),
                padding: EdgeInsets.zero,
                constraints: BoxConstraints(),
              ),
            ],
          ),

          SizedBox(height: 10.h),

          // 提示文本
          Text(
            'Please select a reason for your report:',
            style: TextStyle(color: Colors.white70, fontSize: 14.sp),
          ),

          SizedBox(height: 15.h),

          // 举报原因列表
          Container(
            constraints: BoxConstraints(maxHeight: Get.height * 0.6),
            child: SingleChildScrollView(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children:
                    ReportReason.values
                        .map((reason) => _buildReportItem(reason))
                        .toList(),
              ),
            ),
          ),

          SizedBox(height: 20.h),
        ],
      ),
    );
  }

  // 构建举报项目
  Widget _buildReportItem(ReportReason reason) {
    return InkWell(
      onTap: () => onReport(reason),
      child: Container(
        width: double.infinity,
        padding: EdgeInsets.symmetric(vertical: 12.h),
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(color: Colors.white.withOpacity(0.1), width: 1),
          ),
        ),
        child: Text(
          reason.englishName,
          style: TextStyle(color: Colors.white, fontSize: 16.sp),
        ),
      ),
    );
  }
}
